import { unref } from 'vue';

export function transformTreeData(treeData, isUpdate, data) {
  treeData.forEach((item) => {
    item['value'] = item.id;
    item['key'] = item.id;
    item['label'] = item.name;
    if (unref(isUpdate)) {
      item['selectable'] = data.record.id !== item.id;
    }
    if (item.hasOwnProperty('children')) {
      transformTreeData(item.children, isUpdate, data);
    }
  });
}

export function removeButton(treeData: any[]) {
  let index = treeData.length;
  while (index--) {
    const data = treeData[index];
    if (data.type == 2) {
      treeData.splice(index, 1);
    }
    if (data.hasOwnProperty('children')) {
      removeButton(data.children);
    }
  }
  return treeData;
}
